package com.ruoyi.common.utils.Test;

import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.binary.Base64;

public class tese {


    public static void main(String[] args)  throws Exception{
        httpsPrivacyBindAxb();//绑定号码

//        httpsPrivacyUnbind();
    }

    public static VoiceResponseResult httpsPrivacyBindAxb() throws Exception {

        /** AXB模式小号绑定接口地址*/

        String url = "https://101.37.133.245:11008/voice/1.0.0/middleNumberAXB";

        PrivacyBindBodyAxb bindBodyAxb = new PrivacyBindBodyAxb();

        /** 设定绑定的隐私小号*/
        bindBodyAxb.setMiddleNumber("02160592285");
        /** 设定与该隐私小号绑定的号码A*/
        bindBodyAxb.setBindNumberA("18518671562");
        /** 设定与该隐私小号绑定的号码B*/
        bindBodyAxb.setBindNumberB("13683150995");
        /** 设置是否开启通话录音  1:开启，0:关闭*/
        bindBodyAxb.setCallRec(0);
        /** 设置绑定关系有效时长 ,为空表示绑定关系永久，单位:秒*/
//        bindBodyAxb.setMaxBindingTime();
        /** 设置是否透传主叫的号码到A  0:不透传; 1: 透传，不填默认不透传*/
        bindBodyAxb.setPassthroughCallerToA(0);
        /** 设置是否透传主叫的号码到B  0:不透传; 1: 透传，不填默认不透传*/
        bindBodyAxb.setPassthroughCallerToB(0);

        //提示结束时间
        bindBodyAxb.setMaxCallDuration(600);
//        /** 设置用于接收呼叫结果的服务地址*/
//        bindBodyAxb.setCallbackUrl();

        /** 获取当前系统时间戳*/
        long timestamp = System.currentTimeMillis();
        /** 生成Base64转码后的参数authorization*/
        String name = 494608+":"+timestamp;
        byte[] bytes = name.getBytes();

        String authorization = Base64.encodeBase64String(bytes);
        /** 生成加密参数sig*/
        String sig = MD5Util.getMD5(494608 + "f2734eb26d1f4fa4a7e3b8ab8396d4e5" + timestamp);

        /** 生成最终接口访问地址*/
        url = url + "/" + 494608 + "/" + sig;

        String body = JSON.toJSONString(bindBodyAxb);

        /** 调用接口*/
        HttpsService httpsService = new HttpsService();
        String result = httpsService.doPost(url, authorization, body, "UTF-8");
        System.out.println(result);

        return null;

    }


    public static VoiceResponseResult httpsPrivacyUnbind() throws Exception {

        /** 小号解绑接口地址*/
        String url = "https://101.37.133.245:11008/voice/1.0.0/middleNumberUnbind";

        PrivacyUnbindBody unbindBody = new PrivacyUnbindBody();
        /** 获取当前系统时间戳*/
        long timestamp = System.currentTimeMillis();

        /** 设置需要解绑的小号*/
        unbindBody.setMiddleNumber("02160592285");
        /** 设定与该隐私小号绑定的号码A*/
        unbindBody.setBindNumberA("13683150995");
        /** 设定与该隐私小号绑定的号码B*/
        unbindBody.setBindNumberB("18518671562");

        String name = 494608+":"+timestamp;
        byte[] bytes = name.getBytes();
        /** 生成Base64转码后的参数authorization*/
        String authorization = Base64.encodeBase64String(bytes);

        /** 生成加密参数sig*/
        String sig = MD5Util.getMD5(494608 + "f2734eb26d1f4fa4a7e3b8ab8396d4e5" + timestamp);

        /** 生成最终接口访问地址*/
        url = url + "/" + 494608 + "/" + sig;

        String body = JSON.toJSONString(unbindBody);

        /** 调用接口解绑小号*/
        HttpsService httpsService = new HttpsService();
        String result = httpsService.doPost(url, authorization, body, "UTF-8");
        System.out.println("----------------------------------"+result);

        return  null;

    }


}
